/*   1:    */ package gov.sat.tax.fwsk.wlrz;
/*   2:    */ 
/*   3:    */ import java.io.BufferedReader;
/*   4:    */ import java.io.IOException;
/*   5:    */ import java.io.InputStreamReader;
/*   6:    */ import java.io.PrintStream;
/*   7:    */ import java.util.ArrayList;
/*   8:    */ import java.util.List;
/*   9:    */ 
/*  10:    */ public class JmjPoolCycle
/*  11:    */ {
/*  12: 11 */   private static List jmjs = new ArrayList();
/*  13: 12 */   private static List hyJmjs = new ArrayList();
/*  14: 13 */   private static JmjPoolCycle pool = null;
/*  15:    */   
/*  16:    */   private JmjPoolCycle()
/*  17:    */   {
/*  18: 16 */     BufferedReader fi = null;
/*  19: 17 */     BufferedReader hyfi = null;
/*  20:    */     try
/*  21:    */     {
/*  22: 20 */       fi = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/JmServer.ini")));
/*  23:    */     }
/*  24:    */     catch (NullPointerException e)
/*  25:    */     {
/*  26: 22 */       System.out.println("专/普票解密机IP");
/*  27: 23 */       fi = null;
/*  28:    */     }
/*  29: 25 */     if (fi != null)
/*  30:    */     {
/*  31: 26 */       String ajmj = "";
/*  32: 27 */       System.out.println("----------------专/普票解密机队列初始化---------------");
/*  33:    */       try
/*  34:    */       {
/*  35: 29 */         int i = 0;
/*  36: 30 */         while ((ajmj = fi.readLine()) != null)
/*  37:    */         {
/*  38: 32 */           ajmj = ajmj.trim();
/*  39: 33 */           if (ajmj.toUpperCase().startsWith("SERVER")) {
/*  40: 34 */             jmjs.add(new JmjBean(ajmj.substring(ajmj.indexOf(":") + 1), 200, i++, true));
/*  41:    */           } else {
/*  42: 36 */             jmjs.add(new JmjBean(ajmj, 1, i++, false));
/*  43:    */           }
/*  44: 38 */           System.out.println("[INFO] " + ajmj);
/*  45:    */         }
/*  46: 40 */         System.out.println("--------------专/普票解密机队列初始化结束-------------");
/*  47:    */       }
/*  48:    */       catch (IOException e)
/*  49:    */       {
/*  50: 42 */         System.out.println("[ERROR] 专/普票解密机配置文件出现异常 " + e.toString());
/*  51: 43 */         e.printStackTrace();
/*  52:    */       }
/*  53:    */     }
/*  54:    */     try
/*  55:    */     {
/*  56: 48 */       hyfi = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/hyJmServer.ini")));
/*  57:    */     }
/*  58:    */     catch (NullPointerException e)
/*  59:    */     {
/*  60: 50 */       System.out.println("无货运解密配置文件");
/*  61: 51 */       hyfi = null;
/*  62:    */     }
/*  63: 53 */     if (hyfi != null)
/*  64:    */     {
/*  65: 54 */       String hyjmj = "";
/*  66: 55 */       System.out.println("----------------货运解密机队列初始化------------------");
/*  67:    */       try
/*  68:    */       {
/*  69: 57 */         int i = 0;
/*  70: 58 */         while ((hyjmj = hyfi.readLine()) != null)
/*  71:    */         {
/*  72: 60 */           hyjmj = hyjmj.trim();
/*  73: 61 */           if (hyjmj.toUpperCase().startsWith("SERVER")) {
/*  74: 62 */             hyJmjs.add(new JmjBean(hyjmj.substring(hyjmj.indexOf(":") + 1), 200, i++, true));
/*  75:    */           } else {
/*  76: 64 */             hyJmjs.add(new JmjBean(hyjmj, 1, i++, false));
/*  77:    */           }
/*  78: 66 */           System.out.println("[INFO] " + hyjmj);
/*  79:    */         }
/*  80: 68 */         System.out.println("----------------货运解密机队列初始化结束--------------");
/*  81:    */       }
/*  82:    */       catch (IOException e)
/*  83:    */       {
/*  84: 70 */         System.out.println("[ERROR] 读取货运解密机配置文件出现异常 " + e.toString());
/*  85: 71 */         e.printStackTrace();
/*  86:    */       }
/*  87:    */     }
/*  88:    */   }
/*  89:    */   
/*  90:    */   public static JmjPoolCycle createInstance()
/*  91:    */   {
/*  92: 77 */     if (pool != null) {
/*  93: 78 */       return pool;
/*  94:    */     }
/*  95: 80 */     pool = new JmjPoolCycle();
/*  96: 81 */     return pool;
/*  97:    */   }
/*  98:    */   
/*  99:    */   public synchronized JmjBean getJmj()
/* 100:    */   {
/* 101: 86 */     JmjBean tmpJmjBean = null;
/* 102: 87 */     for (int i = 0; i < jmjs.size(); i++)
/* 103:    */     {
/* 104: 89 */       tmpJmjBean = (JmjBean)jmjs.get(i);
/* 105: 90 */       if (tmpJmjBean.isAvailable())
/* 106:    */       {
/* 107: 92 */         tmpJmjBean.addWork();
/* 108: 93 */         break;
/* 109:    */       }
/* 110: 95 */       tmpJmjBean = null;
/* 111:    */     }
/* 112: 97 */     if (tmpJmjBean == null) {
/* 113: 98 */       System.out.println("[WARN] 无可用专/普票解密机");
/* 114:    */     } else {
/* 115:100 */       System.out.println("[getJmj] " + tmpJmjBean.getJmjIP());
/* 116:    */     }
/* 117:102 */     return tmpJmjBean;
/* 118:    */   }
/* 119:    */   
/* 120:    */   public synchronized JmjBean getHyJmj()
/* 121:    */   {
/* 122:106 */     JmjBean tmpJmjBean = null;
/* 123:107 */     for (int i = 0; i < hyJmjs.size(); i++)
/* 124:    */     {
/* 125:109 */       tmpJmjBean = (JmjBean)hyJmjs.get(i);
/* 126:110 */       if (tmpJmjBean.isAvailable())
/* 127:    */       {
/* 128:112 */         tmpJmjBean.addWork();
/* 129:113 */         break;
/* 130:    */       }
/* 131:115 */       tmpJmjBean = null;
/* 132:    */     }
/* 133:117 */     if (tmpJmjBean == null) {
/* 134:118 */       System.out.println("[WARN] 无可用货运解密机");
/* 135:    */     } else {
/* 136:120 */       System.out.println("[getHyJmj] " + tmpJmjBean.getJmjIP());
/* 137:    */     }
/* 138:122 */     return tmpJmjBean;
/* 139:    */   }
/* 140:    */   
/* 141:    */   public synchronized boolean releaseJmj(JmjBean jb)
/* 142:    */   {
/* 143:126 */     boolean rtn = true;
/* 144:127 */     if (jb != null)
/* 145:    */     {
/* 146:128 */       jb.removeWork();
/* 147:129 */       System.out.println("[ResJmj] " + jb.getJmjIP());
/* 148:    */     }
/* 149:131 */     return rtn;
/* 150:    */   }
/* 151:    */ }


/* Location:           D:\htjs\document\wsrz\WsrzEjbInf\
 * Qualified Name:     gov.sat.tax.fwsk.wlrz.JmjPoolCycle
 * JD-Core Version:    0.7.0.1
 */